package org.huawei260.OD260;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @Auther: qingle
 * @Date: 2024/8/21-23:58
 * @Description:
 *
 *
 * @version: 1.0
 */



public class O0014_单词接龙_AI {

		// 用于记录最长的单词链长度
		private static int maxLength = 0;
		// 用于记录最长的单词链
		private static String longestChain = "";

		public static void main(String[] args) {
			Scanner scanner = new Scanner(System.in);
			int N = scanner.nextInt(); // 读取单词数量
			scanner.nextLine(); // 消耗掉换行符

			String[] words = new String[N];
			for (int i = 0; i < N; i++) {
				words[i] = scanner.nextLine(); // 读取每个单词
			}

			boolean[] visited = new boolean[N]; // 用于标记单词是否被访问
			for (int i = 0; i < N; i++) {
				// 从每个单词开始进行DFS
				dfs(words, visited, i, words[i], words[i].length());
			}

			System.out.println(longestChain); // 输出最长的单词链
		}

		private static void dfs(String[] words, boolean[] visited, int currentIndex, String currentChain, int currentLength) {
			visited[currentIndex] = true; // 标记当前单词已访问

			for (int i = 0; i < words.length; i++) {
				// 检查是否可以连接下一个单词
				if (!visited[i] && words[currentIndex].charAt(words[currentIndex].length() - 1) == words[i].charAt(0)) {
					// 递归调用DFS，继续构建单词链
					dfs(words, visited, i, currentChain + words[i], currentLength + words[i].length());
				}
			}

			// 更新最长单词链
			if (currentLength > maxLength) {
				maxLength = currentLength;
				longestChain = currentChain;
			}

			visited[currentIndex] = false; // 回溯，取消当前单词的访问标记
		}
	}